package com.erp.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.erp.service.PrivilegeService;

public class InitServletContextListener implements ServletContextListener {
	
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("正在准备权限数据...");
		ServletContext application = sce.getServletContext();
		ApplicationContext ac = WebApplicationContextUtils
				.getWebApplicationContext(application);
		PrivilegeService privilegeService = (PrivilegeService) ac
				.getBean("privilegeService");
		application.setAttribute("privilegeList", privilegeService.list());
		
		System.out.println("加载完毕");
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("系统已退出");
	}

}
